<?php
namespace Partner\Controller;

use Utuo\BackgroundController;

class ProductCategoryConfigController extends BackgroundController {
	
	public function _initialize() {
		$this->setControllerTitle("栏目配置");
		$this->setActionTitle(array(
				'index' => '栏目配置',
		));
		$this->setActionNav("index");
	}
	
	public function indexAction() {
		$id = I('id', 0, 'intval');
		$productCategoryConfig = M("ProductCategoryConfig a")->join("__PRODUCT_CATEGORY__ b on a.id=b.id")->where(array('b.partner'=>$this->aid, 'a.id'=>$id))->find();
		if ( !$productCategoryConfig ) {
			$productCategory = M("ProductCategory")->where(array('partner'=>$this->aid, 'id'=>$id))->find() or $this->error("无效栏目!");
			if ( $productCategory ) {
				$productCategoryConfig = array(
						'id' => $productCategory['id'],
						'pid' => $productCategory['partner'],
						'page_title' => $productCategory['name'],
						'page_keywords' => $productCategory['name'],
						'page_content' => "",
				);
				false !== M("ProductCategoryConfig")->add( $productCategoryConfig ) or $this->error("初始数据失败!");
			}
		}
		$this->assign("productCategoryConfig", $productCategoryConfig);
		$this->display();
	}
	
	public function saveAction() {
		$this->submitPost("ProductCategoryConfig");
	}
	
}